package day0721;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

//集合中存储的都是对象
public class Test3 {
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();

        Student  zs=new Student("张三",1.75);
        list.add(zs);
        System.out.println(list);
        Student  zs2=new Student("张三",1.75);
        System.out.println(list.contains(zs2));

        zs.setHeight(1.85);
        System.out.println(list);
        //集合中存储的都是对象， 通过对象某一个引用修改对象， 集合中的数据会跟着改变

        list.add(new Student("李四",1.75));
        System.out.println(list);

        Student lisi=new Student("李四",1.75);
        System.out.println(list.contains(lisi));


        Student wangWu=new Student("王五",1.75);
        list.add(wangWu);

        Student ww=new Student("王五",1.75);
        System.out.println(list.contains(ww));

        list.remove(new Student("王五",1.75));
        System.out.println(list);

    }
}









class Student implements Serializable {
    private String name;//1.成员变量
    private double height;
    public Student() { }
    //2.构造     3.get  set方法      4.hashCode  equals    5.toString
    public Student(String name, double height) {
        this.name = name;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Double.compare(student.height, height) == 0 && Objects.equals(name, student.name);
    }

    public int hashCode() {
        return Objects.hash(name, height);
    }

    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", height=" + height +
                '}';
    }
}
